﻿Imports System.Data
Imports System.Data.SqlClient
Imports System.ComponentModel

Public Class KetQuaDAO
    Public Sub LoadCombobox(ByVal cbx As ComboBox, ByVal sql As String)
        Dim load As DataProvider = New DataProvider
        cbx.DataSource = load.Sql_ExecuteTable(sql)
    End Sub
    Public Sub LoadGridView(ByVal dgv As DataGridView, ByVal sql As String)
        Dim load As DataProvider = New DataProvider
        dgv.DataSource = load.Sql_ExecuteTable(sql)
    End Sub
    Public Function ThemKetQua(ByVal kqInsert As KetQuaDTO) As Boolean
        Dim Insert As DataProvider = New DataProvider
        Dim sql As String = String.Format("Insert_KetQua")
        Dim pr As SqlParameter() = {New SqlParameter("@MaHocSinh", kqInsert.MaHocSinh),
                                  New SqlParameter("@MaMonHoc", kqInsert.MaMonHoc),
                                  New SqlParameter("@MaHocKy", kqInsert.MaHocKy),
                                  New SqlParameter("@Diem15Phut", kqInsert.Diem15Phut),
                                  New SqlParameter("@Diem45Phut", kqInsert.Diem45Phut),
                                  New SqlParameter("@DiemCuoiKy", kqInsert.DiemCK),
                                  New SqlParameter("@TBCuoiKy", kqInsert.TBCK)}
        Dim cmd As SqlCommand = New SqlCommand(sql)
        cmd.CommandType = CommandType.StoredProcedure
        For i As Integer = 0 To pr.Count() - 1
            cmd.Parameters.Add(pr(i))
        Next
        Return Insert.SQL_ExecuteNonQuery(cmd)
    End Function
    Public Function XoaKetQua(ByVal MaHocSinh As String, ByVal MaMonHoc As String, ByVal MaHocKy As String) As Boolean
        Dim Remove As DataProvider = New DataProvider
        Dim sql As String = String.Format("Remove_KetQua")
        Dim pr As SqlParameter() = {New SqlParameter("@MaHocSinh", MaHocSinh),
                                 New SqlParameter("@MaMonHoc", MaMonHoc),
                                 New SqlParameter("@MaHocKy", MaHocKy)}
        Dim cmd As SqlCommand = New SqlCommand(sql)
        cmd.CommandType = CommandType.StoredProcedure
        For i As Integer = 0 To pr.Count() - 1
            cmd.Parameters.Add(pr(i))
        Next
        Return Remove.SQL_ExecuteNonQuery(cmd)
    End Function
    Public Function SuaKetQua(ByVal kqUpdate As KetQuaDTO) As Boolean
        Dim Update As DataProvider = New DataProvider
        Dim sql As String = String.Format("Update_KetQua")
        Dim pr As SqlParameter() = {New SqlParameter("@MaHocSinh", kqUpdate.MaHocSinh),
                                  New SqlParameter("@MaMonHoc", kqUpdate.MaMonHoc),
                                  New SqlParameter("@MaHocKy", kqUpdate.MaHocKy),
                                  New SqlParameter("@Diem15Phut", kqUpdate.Diem15Phut),
                                  New SqlParameter("@Diem45Phut", kqUpdate.Diem45Phut),
                                  New SqlParameter("@DiemCuoiKy", kqUpdate.DiemCK),
                                  New SqlParameter("@TBCuoiKy", kqUpdate.TBCK)}
        Dim cmd As SqlCommand = New SqlCommand(sql)
        cmd.CommandType = CommandType.StoredProcedure
        For i As Integer = 0 To pr.Count() - 1
            cmd.Parameters.Add(pr(i))
        Next
        Return Update.SQL_ExecuteNonQuery(cmd)
    End Function
    Public Function GetList() As BindingList(Of KetQuaDTO)
        Dim _ListKetqua As New BindingList(Of KetQuaDTO)
        Dim GetDT As DataProvider = New DataProvider
        Dim sql As String = "select MaHocSinh, MaMonHoc, MaHocKy, Diem15Phut, Diem45Phut, DiemCuoiKy from KETQUA"
        Dim rd As SqlDataReader
        rd = GetDT.SQL_ExcuteQueryReader(sql)
        While rd.Read()
            Dim item As New KetQuaDTO()
            item.MaHocSinh = rd.GetString(0)
            item.MaMonHoc = rd.GetString(1)
            item.MaHocKy = rd.GetString(2)
            item.Diem15Phut = rd.GetDouble(3)
            item.Diem45Phut = rd.GetDouble(4)
            item.DiemCK = rd.GetDouble(5)
            _ListKetqua.Add(item)
        End While
        Return _ListKetqua
    End Function
End Class
